{% macro select(id,list,value,class='',style='',blank_option=true) -%}
	<select name="{{id}}" id="{{id}}" class="{{class}}" style="{{style}}">
		{% if blank_option %}
          <option value=""></option>
        {% endif %}
          {% for o in list%}
              {% if o.id == value%}
                  <option value="{{o.id}}" selected="selected">{{o}}</option>
              {% else %}
                  <option value="{{o.id}}">{{o}}</option>
              {% endif %}
          {% endfor %}
      </select>
{%- endmacro %}


{% macro render_field(field) -%} 
    <div class="control-group">
        <label class="control-label">{{ field.label }}</label>
        <div class="controls">{{ field(**kwargs)|safe }}</div>
    </div>
{%- endmacro %}

{% macro render_required_field(field) -%} 
    <div class="control-group">
        <label class="control-label">{{ field.label }}<span style='color:red'>*</span></label>
        <div class="controls">{{ field(**kwargs)|safe }}</div>
    </div>
{%- endmacro %}


{% macro render_field_with_errors(field) -%}
    <div class="control-group {% if field.errors %}error{% endif %}">
        <label class="control-label" for="{{ field.id }}">
            {{ field.label.text }}
        </label>
        <div class="controls">
            {{ field(**kwargs)|safe }}
            {% if field.errors %}
                <span class="help-inline">
                    {% for error in field.errors %}
                        {{ error }}
                    {% endfor %}
                </span>
            {% endif %}
        </div>
    </div>
{%- endmacro %}



{% macro render_search_form(form,span=6) -%}
    <form method="POST" action="{{form.url}}" class="searchForm">
        {% for field in form %}
            {% if field.type == 'HiddenField' %}
                {{ field(**kwargs)|safe }}
            {% else %}
                <div class="col-md-{{span}}">
                    <!--<div class="control-group{{' error' if field.flags.required else ''}} controls-row"> -->
                    <div class="form-group">
                        <label class="control-label" for="{{field.id}}">{{ field.label }}</label>
                        <div class="controls">{{ field(class_='form-control',**kwargs)|safe }}</div>
                    </div>
                </div>
            {% endif %}
        {% endfor %}
    </form>
{%- endmacro %}



{% macro mypaginate(records) -%}
    <div class="pagination pull-right">
      {{records.pager(format='$link_first $link_previous ~5~ $link_next $link_last, 共计 $item_count 条记录',
                        show_if_single_page=True,
                        symbol_first='第一页',
                        symbol_last='最后一页',
                        symbol_previous='上一页',
                        symbol_next='下一页')}}&nbsp;&nbsp;
    </div>
    <div class="clearfix"></div>
{%- endmacro %}



{% macro render_pdt_tds(info) -%}
    <td><a href="{{url_for('',action='viewByNo',no=info.pdtno)}}">{{info.pdtno}}</a></td>
    <td>{{info.pdtname}}</td>
    <td>{{info.pdttype|f}}</td>
    <td>{{info.pdtstyleNo|f}}</td>
    <td>{{info.pdtcertificate|f}}</td>
{%- endmacro %}


{% macro render_log(records) -%}
    <table class="table table-bordered">
        <thead>
            <tr>
                <td>时间</td>
                <td>操作人</td>
                <td>操作类型</td>
                <td class="col-md-8">日志</td>
            </tr>
        </thead>
        <tbody>
            {% for l,u in records %}
                <tr>
                    <td>{{l.sysCreateTime|ft}}</td>
                    <td>{{u}}</td>
                    <td>{{l.type|ss(c='LOG')}}</td>
                    <td>{{(l.remark or '').replace('\n','<br />')|safe}}</td>
                </tr>
            {% endfor %}
        </tbody>                
    </table>
{%- endmacro %}


{% macro render_module(label,url,img) -%}
    <div class="col-md-3" style="padding-bottom: 20px">
        <div class="thumbnail">
          <a href="{{url}}"><img alt="{{label}}" src="{{url_for('static', filename='img/system/%s' %img)}}"></a>
          <div class="caption">
            <h3>{{label}}</h3>
            <p class="text-right"><a href="{{url}}" class="btn btn-primary">{{BTN_ENTER}}</a></p>
          </div>
        </div>
    </div>
{%- endmacro %}


{% macro render_thumb(obj, showDiv=False) -%}
{% if showDiv %}
<div style='float:left;width:52px;height:50px;'>
{% endif %}
    {% if obj.realImgID %}
        <a href="{{obj.realImg.url}}"  class="colorbox"><img src="{{obj.thumb.url}}"/></a>
    {% else %}
        <img src="{{url_for('static', filename='img/system/noimage.jpg')}}" style="width:50px;height:50px"/>
    {% endif %}
{% if showDiv %}
</div>
{% endif %}
{%- endmacro %}


{% macro render_gallery(obj=None, init=True) -%}
{% if init %}
<link rel="stylesheet" href="{{url_for('static', filename='css/gallery/gallery.css')}}">
<link rel="stylesheet" href="{{url_for('static', filename='css/gallery/elastislide.css')}}">
<script type='text/javascript' src="{{url_for('static', filename='js/gallery/jquery.tmpl.min.js')}}"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/gallery/jquery.elastislide.js')}}"></script>
<script type='text/javascript' src="{{url_for('static', filename='js/gallery/gallery.js')}}"></script>
<script id="img-wrapper-tmpl" type="text/x-jquery-tmpl">    
    <div class="rg-image-wrapper">
        {{ '{{if itemsCount > 1}}'|safe }}
            <div class="rg-image-nav">
                <a href="#" class="rg-image-nav-prev">Previous Image</a>
                <a href="#" class="rg-image-nav-next">Next Image</a>
            </div>
        {{ '{{/if}}' }}
        <div class="rg-image"></div>
        <div class="rg-loading"></div>
        <div class="rg-caption-wrapper">
            <div class="rg-caption" style="display:none;">
                <p></p>
            </div>
        </div>
    </div>
</script>
{% endif %}
{% if obj.image %}
<div id="rg-gallery" class="rg-gallery">
    <div class="rg-thumbs">
        <div class="es-carousel-wrapper">
            <div class="es-carousel">
                <ul>
                    {% if obj.image %}
                        {% for a in obj.image %}
                        <li><a href="javascript:alert('xxx')"><img src="{{ a.url }}" data-large="{{ a.url }}"></a></li>
                        {% endfor %}
                    {% endif %}
                </ul>
            </div>
            <div class="es-nav">
                <span class="es-nav-prev">Previous</span>
                <span class="es-nav-next">Next</span>
            </div>
        </div>
    </div>
</div>
{% endif %}
{%- endmacro %}


{% macro render_goto_popup(no=None, init=True) -%}
{% if no %}
<div style='width:150px;'>
    <a href="javascript:pupupGoto('{{ no }}')">{{ no }}<i class='glyphicon glyphicon-eye-open'></i></a>
</div>
{% endif %}
{% if init %}
<script type='text/javascript'>
function pupupGoto(no){
    var url = $('#modalPopupGoto').attr('url')
    $.ajax({
        url: url+'?q='+no,
        success: function(data) {
            $('#modalPopupGoto').html(data)
            $('#modalPopupGoto').modal()
        }
    });
}
</script>
<div id="modalPopupGoto" class="modal hide fade" url="{{ url_for('bpAjax.view', action='popupGoto') }}" 
    style='width:860px;margin-left:-430px;'></div>
{% endif %}
{%- endmacro %}


{% macro render_goto_popup_pdt(obj=None, init=True) -%}
{% if obj %}
{{ render_thumb(obj, True) }}
<div style='float:left;width:150px;'>
    <a href="javascript:pupupGoto('{{ obj.no }}')">{{ obj.no }}<i class='glyphicon glyphicon-eye-open'></i></a>
</div>
<br/>
{% endif %}
{{ render_goto_popup(None, init) }}
{%- endmacro %}


{% macro render_recent_price_popup(obj=None, init=True, name='') -%}
{% if obj %}
<a href="javascript:popupRecentPrice('{{ obj.no }}', '{{ name }}')"><i class="glyphicon glyphicon-time"></i></a>
{% endif %}
{% if init %}
<script type='text/javascript'>
function popupRecentPrice(no, name){
    var url = $('#modalPopupRecentPrice').attr('url');
    $.ajax({
        url: url+'?q='+no+'&name='+name,
        success: function(data) {   
            $('#modalPopupRecentPrice').html(data)
            $('#modalPopupRecentPrice').modal()
        }
    });
}
</script>
<div id="modalPopupRecentPrice" class="modal hide fade" url="{{ url_for('bpAjax.view', action='popupRecentPrice') }}" 
    style='width:860px;margin-left:-430px;'></div>
{% endif %}
{%- endmacro %}


{% macro render_recent_prh_price() -%}
<!-- modal begin -->
<script src="{{url_for('static', filename='js/customize/pdt_recent.js')}}?v=aa" type="text/javascript"></script>
<div id="appModal" class="modal hide fade" style="display: none;">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    最近商品采购价格
  </div>
  <div class="modal-body">
    <div class="col-md-10">
        <table class="table table-bordered">
                <tr class="success">
                    <td class="col-md-2">采购日期</td>
                    <td class="col-md-2">采购单号</td>
                    <td class="col-md-2">商品编号</td>
                    <td class="col-md-2">商品名称</td>
                    <td class="col-md-1">采购价格</td>
                    <td class="col-md-1">经办人</td>
                </tr>
            <tbody id="data_list"></tbody>
        </table>
    </div>
  </div>
  <div class="modal-footer">
    <button type="button" data-dismiss="modal" class="btn btn-primary">{{BTN_CLOSE}}</button>
  </div>
</div>
<!-- modal end -->
{%- endmacro %}



{% macro render_system_info(obj) -%}
    <fieldset>
        <legend>系统信息</legend>
            <div class="col-md-3"><h4>录入时间</h4><p>{{obj.sysCreateTime|ft}}</p></div>
            <div class="col-md-3"><h4>录入人</h4><p>{{obj.createBy|f}}</p></div>
            <div class="col-md-3"><h4>更新时间</h4><p>{{obj.updateTime|ft}}</p></div>
            <div class="col-md-3"><h4>更新人</h4><p>{{obj.updateBy|f}}</p></div>
    </fieldset>
{%- endmacro %}



{% macro render_atm(a) -%}
    {% if isImage(a.name) %}
        <a href="{{a.url}}"  class="colorbox">{{a.name}}</a>
    {% else %}
        <a href="{{url_for('bpRoot.view',action='dl',id=a.id)}}">{{a.name}}</a>
    {% endif %}
{%- endmacro %}


{% macro render_preview_all_attachment(files) -%}    
        <div class="row">
        {% for a in files %}
            <div class="col-md-1">
                <p>      
                {% if isImage(a.name) %}
                    <a href="{{a.url}}"  class="colorbox" title="{{a.name}}"><img src="{{a.url}}" style="width:50px;height:50px"/></a>
                {% else %}
                    <a href="{{url_for('bpRoot.view',action='dl',id=a.id)}}" title="{{a.name}}"><img src="{{url_for('static', filename='img/system/download.jpg')}}" style="width:50px;height:50px"/></a>
                {% endif %}
                </p>
            </div>
        {% endfor %}
        </div>
{%- endmacro %}


{% macro render_edit_all_attachment(files,jsobj='attachment',parent_cls='extatm') -%}    
        <div class="row">
        {% for a in files %}
            <div class="col-md-1 {{parent_cls}}">
                <p class="">      
                {% if isImage(a.name) %}
                    <a href="{{a.url}}"  class="colorbox" title="{{a.name}}"><img src="{{a.url}}" style="width:50px;height:50px"/></a>
                {% else %}
                    <a href="{{url_for('bpRoot.view',action='dl',id=a.id)}}" title="{{a.name}}"><img src="{{url_for('static', filename='img/system/download.jpg')}}" style="width:50px;height:50px"/></a>
                {% endif %}
                </p>
                    <button type="button" class="btn btn-default" onclick="delExtAtm(this,{{a.id}},'{{jsobj}}','{{parent_cls}}')"><li class="glyphicon glyphicon-trash"></li></button>
            </div>
        {% endfor %}
        </div>
{%- endmacro %}


{% macro render_item_trace(item) -%}
    <a href="{{url_for('bpTrc.view',action='index',no=item.no)}}" target="_blank">{{item.no}}</a>
{%- endmacro %}